<?php
/**
 * Log4 日志记录类
 * @author hVenus
 *
 * 记录日志
 * 默认记录在当前目录下的log4.log文件中.
 * 通过setLogPath()设置记录的文件，包括路径。
 * eg. setLogPath('c:\x.log')
 * 
 */

class log4{
	
	private $_log_path = '.';
	private $_log_file_path = 'log4.log';
	private $_file_size = 4096;
	
	public function __construct(){
		$this->log4();
	}
	
	public function log4(){
		
	}
	
	/* 设置日志文件 */
	public function setLogPath($path){
		$this->_log_file_path = $path;
	}
	
	/* 取日志文件 */
	public function getLogPath(){
		return $this->_log_file_path;
	}
	
	/* 记录日志 */
	public function logMsg($msg){
		//$this->trimLogfile();
		$fp = fopen($this->_log_file_path, 'a+b');
		fwrite($fp, date('Y-m-d H:i:s',time()).' ');
		
		if(is_array($msg)){
			$s = var_export($msg, true);
			fwrite($fp, $s);
		}else{
			fwrite($fp, $msg);
		}
		
		fwrite($fp, "\r\n");
		fclose($fp);
	}
	
	/* trim logfile */
	private function trimLogfile(){
		$fp = fopen($this->_log_file_path, 'wb');
		fwrite($fp, date('Y-m-d H:i:s',time()).' ');
		
		
		
		fwrite($fp, "\r\n");
		fclose($fp);
	}
	
}
?>